package com.android.dialer.extendboard;

import android.os.Parcel;
import android.os.Parcelable;

public class ServiceMessage implements Parcelable {
    private int messageType;
    private byte[] data;

    public ServiceMessage(int messageType, byte[] data) {
        this.messageType = messageType;
        this.data = data;
    }

    protected ServiceMessage(Parcel in) {
        messageType = in.readInt();
        data = in.createByteArray();
    }

    public static final Creator<ServiceMessage> CREATOR = new Creator<ServiceMessage>() {
        @Override
        public ServiceMessage createFromParcel(Parcel in) {
            return new ServiceMessage(in);
        }

        @Override
        public ServiceMessage[] newArray(int size) {
            return new ServiceMessage[size];
        }
    };

    public int getMessageType() {
        return messageType;
    }

    public void setMessageType(int messageType) {
        this.messageType = messageType;
    }

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(messageType);
        dest.writeByteArray(data);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("ServiceMessage{");
        sb.append("messageType=").append(messageType);
        sb.append(", data=");
        if (data != null) {
            for (byte b : data) {
                sb.append(String.format("%02X ", b));
            }
        } else {
            sb.append("null");
        }
        sb.append('}');
        return sb.toString();
    }
}
